home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Purity / Purity #42 (1995-01)(PackMAN)(DE)[WB].zip / Purity #42 (1995-01)(PackMAN)(DE)[WB].adf / Includes3v1 / Includes3v1.lha / Utils / RunProgram.i < prev    next >
Text File  |  1994-12-04  |  4KB  |  118 lines

  1. {
  2.     RunProgram.i
  3.  
  4.     These routines let you run disk files or segments you have loaded
  5.     as seperate processes, which means they can use AmigaDOS just
  6.     like their parent.  Tasks, you will recall, are much simpler but
  7.     can't use any DOS IO routines, which include Write() and Read().
  8.  
  9.     Programs run with these routines think they were run from the Workbench,
  10.     so they must be able to handle that.  The typical CLI commands like
  11.     "dir" and "copy" will NOT work with these routines.  Most PCQ Pascal
  12.     programs should have no problems.
  13.  
  14.     Since these programs are run like Workbench programs, you can't just
  15.     pass along a command line.  That lets out running, for example, the
  16.     Pascal compiler...unless you mess around with the Workbench startup
  17.     message, which will be transparent to the compiler.  That would work
  18.     with some PCQ Pascal programs and probably no others.
  19.  
  20.     Since these routines use the normal PCQ memory allocation schemes,
  21.     the calling program cannot end before all its called programs are
  22.     finished.
  23.  
  24.     The simplest way to use these routines is by calling RunProgram.
  25.     The call looks something like:
  26.  
  27.     if RunProgram("path/filename", 4000) then
  28.         writeln('program ran OK')
  29.     else
  30.         writeln('problem running program');
  31.  
  32.     Remember that not all programs can be run with these routines.  PCQ
  33.     programs probably can, but I wouldn't be surprised if there were
  34.     cases that had problems.
  35.  
  36.     The source code for these routines is in Runtime/Extras
  37. }
  38.  
  39. {  This address is returned by the "No Wait" functions.  It points to
  40.    a record that keeps track of all the memory and other resources
  41.    allocated by the program, and is the key to these routines.  }
  42.  
  43. type
  44.     RunProgPtr = Address;
  45.  
  46.  
  47.  
  48.  
  49. Function RunSegmentNW(ProcName : String;
  50.               Segment : Address;
  51.               StackSize : Integer) : RunProgPtr;
  52.     External;
  53. {
  54.     If you already have a segment loaded, run the segment as a process
  55.     and return immediately.  If something went wrong, this routine
  56.     will return Nil.  Otherwise, the new process is already running by
  57.     the time this routine returns.
  58. }
  59.  
  60.  
  61.  
  62.  
  63. Function RunProgramNW(FileName : String; StackSize : Integer) : RunProgPtr;
  64.     External;
  65. {
  66.     Load a file, then run it as a process.  Return without waiting for
  67.     this new program to complete.  If something goes wrong, this routine
  68.     will return Nil.  Otherwise, the program is running.
  69. }
  70.  
  71.  
  72.  
  73. Procedure FinishProgram(RP : RunProgPtr);
  74.     External;
  75. {
  76.     Wait for the process to finish, then deallocate everything allocated
  77.     by the run routines.  If you started the program with RunSegmentNW
  78.     (i.e. you already had a segment loaded), this routine will not
  79.     UnLoadSeg your segment.  In other words, this routine will deallocate
  80.     everything the run routines allocated, and nothing more.
  81. }
  82.  
  83.  
  84.  
  85. Function RunProgram(FileName : String; StackSize : Integer) : Boolean;
  86.     External;
  87. {
  88.     Run the named program as a process, and wait for that new process
  89.     to finish before returning.  If the process ran OK, this routine
  90.     will return TRUE.  Otherwise it's FALSE.
  91. }
  92.  
  93.  
  94.  
  95. Function RunSegment(ProcName    : String;
  96.             Segment    : Address;
  97.             StackSize    : Integer) : Boolean;
  98.     External;
  99. {
  100.     If for some reason you already have a segment loaded, you can
  101.     call this routine to run that segment as a process, then
  102.     wait for the process to finish before returning.  If something
  103.     goes wrong, this routine will return FALSE.  Otherwise it
  104.     returns TRUE.
  105. }
  106.  
  107.  
  108.  
  109.  
  110. Function ProgramFinished(RP : RunProgPtr) : Boolean;
  111.     External;
  112. {
  113.     If the process indicated by RP is finished, deallocate all the
  114.     memory these routines allocated and return TRUE.  If it's not
  115.     finished, return FALSE.  Like FinishProgram, this routine only
  116.     frees system resources allocated by the RunSomething routines.
  117. }
  118.